﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Model;
using AspNetCs.Bll;
using System.Data;
using System.Collections;
using AspNetCs.Enumerations;
using AspNetCs.Enumerations.memorial_enum;
using AspNetCs.Enumerations.User_Enum;
using AspNetCs.Common;
using AspNetCs.Enumerations.Channel_Enum;


public partial class Users_ArticleList : BasePage
{
    protected int ChannelType = -1;
    protected int ChannelTypeId = 0;
    protected int ArticleType = 0;
    private AspNetCs.Bll.Article bll = new AspNetCs.Bll.Article();
    protected string ArticleImg = "<img src=\"" + configInfo.InstallDir + "Images/class_wsgm.jpg\" />";
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckUserExit("Login.Aspx?ReUrl=" + configInfo.InstallDir + "Users/ArticleList.aspx", "请您登录", true);
        if (!IsPostBack)
        {
            if ((!string.IsNullOrEmpty(Request["ChannelType"])) && (!string.IsNullOrEmpty(Request["ChannelTypeId"])) && (!string.IsNullOrEmpty(Request["ArticleType"])))
            {

            }
            else
            {
                ResultStr("Login.aspx", "参数出错");
            }
            try
            {
                ChannelType = Convert.ToInt32(Request["ChannelType"]);
                ChannelTypeId = Convert.ToInt32(Request["ChannelTypeId"]);
                ArticleType = Convert.ToInt32(Request["ArticleType"]);
                ViewState["ChannelType"] = ChannelType;
                ViewState["ChannelTypeId"] = ChannelTypeId;
                ViewState["ArticleType"] = ArticleType;
                getAritcles();
            }
            catch (Exception ex)
            {

            }
        }
        else
        {
            if (ChannelType == -1 || ChannelTypeId == 0 || ArticleType == 0)
            {
                ChannelType = StringHelper.isNumber_int(ViewState["ChannelType"].ToString());
                ChannelTypeId = StringHelper.isNumber_int(ViewState["ChannelTypeId"].ToString());
                ArticleType = StringHelper.isNumber_int(ViewState["ArticleType"].ToString());
            }
        }
        ImgChange();
    }
    /// <summary>
    /// 栏目切换
    /// </summary>
    protected void ImgChange()
    {
        Channel_Type ChalEum = (Channel_Type)ChannelType;

        switch (ChalEum)
        {
            case Channel_Type.gravestone:
                ArticleImg = "<img src=\"" + configInfo.InstallDir + "Images/class_wsgm.jpg\" />";
                break;
            case Channel_Type.memorial:
                ArticleImg = "<img src=\"" + configInfo.InstallDir + "Images/class_jn.jpg\" />";
                break;
            case Channel_Type.cemetery:
                ArticleImg = "<img src=\"" + configInfo.InstallDir + "Images/class_jz.jpg\" />";
                break;
            case Channel_Type.clan:
                ArticleImg = "<img src=\"" + configInfo.InstallDir + "Images/class_zc.jpg\" />";
                break;

        }

    }

    /// <summary>
    /// 导航切换
    /// </summary>
    /// <returns></returns>
    protected string NavChange()
    {
        string Result = "";
        Channel_Type ChalEum = (Channel_Type)ChannelType;

        switch (ChalEum)
        {
            case Channel_Type.gravestone:
                Result = UI_NetMuMangerNav(ChannelTypeId);
                break;
            case Channel_Type.memorial:
                Result = UI_memorialMangerNav(ChannelTypeId);
                break;
        }

        return Result;
    }

    private void getAritcles()
    {
        try
        {
            Users_Model userModel = Base_GetUserInfo;
            string queryPropertys = " ArticleID,title,CopyFrom,Hits,UpdateTime ";
            int isMaster = 0;

            int EditorId = userModel.UserId;
            Channel_Type ChannelTypeEnum = (Channel_Type)ChannelType;
            DataTable dataTable = bll.getKindsOfArticle(queryPropertys, isMaster, EditorId, ChannelTypeId, ChannelTypeEnum, ArticleType);
            rptAritcleList.DataSource = dataTable;
            rptAritcleList.DataBind();
        }
        catch (Exception ex)
        {
            ResultStr("Login.Aspx?ReUrl=" + configInfo.InstallDir + "Users/ArticleList.aspx", "参数不正确!");
        }

    }

    private bool deleteAritcle(int id)
    {
        return bll.DeleteArticle(id);
    }

    protected void rptAritcleList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        bool bo = false;
        //Response.Write("<script>alert('"+btnDelete.CommandArgument+"');</script>");
        if (e.CommandName == "delete")
        {
            Button btnDelete = e.Item.FindControl("btnDelete") as Button;
            if (btnDelete != null)
            {
                string id = btnDelete.CommandArgument;
                try
                {
                    bo = deleteAritcle(Convert.ToInt32(id));
                }
                catch (Exception ex)
                {
                    bo = false;
                }
            }
        }
        getAritcles();
    }
}
